﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using NLBS.Web.HttpHandlers;
using NLBS.Data;
using NLBS.Entity;
using NLBS.Security;
using NLBS.Data.Business;

namespace NLBS.Blog.Services
{

    public class UserSvc : AjaxHandler
    {

        public string updatePassword(string oldpassword, string password)
        {
            string userName=HttpContext.Current.User.Identity.Name;
           
            User user = UserData.GetUserByName(userName);
            string pass=StringSecurity.StringToSHA1Hash(oldpassword+user.Salt);
            if (!(user.Password == pass))
            {
                throw new Exception("原密码错误");
            }
            user.Password = StringSecurity.StringToSHA1Hash(password + user.Salt);
            UserData.UpdateUser(user);
            
            return string.Empty;
        }

        public string updateUserProFile(int gender, string email, bool hideemail, string homepage)
        {
            string userName = HttpContext.Current.User.Identity.Name;
            
            User user =UserData.GetUserByName(userName);
            user.Gender = gender;
            user.Email = email;
            user.HideEmail = hideemail;
            user.Homepage = homepage;
            UserData.UpdateUser(user);

            return string.Empty;
        }
    }
}
